﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Manage_bidTableAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCheckProjectComp);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
        }

    }
    protected void butSave_Click(object sender, EventArgs e)
    {
        int FieldCount=0;
        string strSql,  BidTableName, BidTableOutlookc, BidTableType, ProductCode;
        double ZL1=0, HL1=0;
        
        BidTableName = SysFun.ToTrim(txtBidTableName.Text);
        BidTableOutlookc = SysFun.ToTrim(txtBidTableOutlookc.Text);
        BidTableType = SysFun.ToTrim(txtBidTableType.Text);
        ProductCode = SysFun.ToTrim(txtProductCode.Text);
       
        if(txtZL1.Text!="")
            ZL1 = Convert.ToDouble(txtZL1.Text);
        if (txtHL1.Text != "")
            HL1 = Convert.ToDouble(txtHL1.Text);
        Db db = new Db();
        System.Data.IDataReader dr;
        strSql = "select count(*) as cun from  bidTable where  ((BidTableName='" + BidTableName + "' and BidTableOutlookc='" + BidTableOutlookc + "' and BidTableType='" + BidTableType + "') or ProductCode='" + ProductCode + "')";
        dr = db.DataReader(strSql);
        if (dr.Read())
        {
            FieldCount = SysFun.ToInt(dr["cun"]);
        }
        dr.Close();
        dr.Dispose();
        if (FieldCount == 0)
        {
            Grove.ORM.ObjectOperator oo = db.GetObjectOperator();
            HZ.MBSM.Model.bidTable bidTable = new HZ.MBSM.Model.bidTable();
            bidTable.BidTableName = BidTableName;
            bidTable.BidTableOutlookc = BidTableOutlookc;
            bidTable.BidTableType = BidTableType;
            bidTable.ProductCode = ProductCode;
            bidTable.ProjectId = 1;
            if (ZL1 > 0)
                bidTable.ZL1 = ZL1;
            if (HL1 > 0)
                bidTable.HL1 = HL1;
            oo.Insert(bidTable);
            oo.Dispose();
            Response.Write("<script>window.opener.location.reload();window.close();</script>");
        }
        else
        {
            Response.Write("<script language=JavaScript>window.alert('该记录在数据库中已经存在！！！！');</script>");
        }
        db.Close();

    }
    protected void butClose_Click(object sender, EventArgs e)
    {
        Response.Write("<script>window.opener.location.reload();window.close();</script>");
    }
}
